﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for DA_PaymentMode
/// </summary>
public class DA_PaymentMode
{
    AuditBillingEntities objABEnt;
    public DA_PaymentMode()
    {
        //
        // TODO: Add constructor logic here
        //
    }

    public List<PLPaymentMode> DA_fnGetPaymentModeList(PLPaymentMode pObjPaymentMode)
    {
        using (objABEnt = new AuditBillingEntities())
        {
            var varRes = (from u in objABEnt.MstPaymentModes
                          where (pObjPaymentMode.SearchIsActive == null || u.IsActive == pObjPaymentMode.SearchIsActive) &&
                                (pObjPaymentMode.PaymentModeID == null || pObjPaymentMode.PaymentModeID == u.MstPaymentModeID) &&
                                (string.IsNullOrEmpty(pObjPaymentMode.PaymentModeName) || u.PaymentModeName.ToLower().Contains(pObjPaymentMode.PaymentModeName.ToLower()))
                          orderby u.PaymentModeName
                          select new PLPaymentMode()
                          {
                              PaymentModeID = u.MstPaymentModeID,
                              PaymentModeName = u.PaymentModeName,
                              IsActive = u.IsActive
                          });
            return varRes.ToList();

        }
    }

    public List<PLPaymentMode> DA_fnGetPaymentModeNameList(PLPaymentMode pObjPaymentMode)
    {
        using (objABEnt = new AuditBillingEntities())
        {
            var varRes = (from u in objABEnt.MstPaymentModes
                          where (pObjPaymentMode.SearchIsActive == null || u.IsActive == pObjPaymentMode.SearchIsActive) &&
                                (pObjPaymentMode.PaymentModeID == null || pObjPaymentMode.PaymentModeID == u.MstPaymentModeID)
                          orderby u.PaymentModeName
                          select new PLPaymentMode()
                          {
                              PaymentModeID = u.MstPaymentModeID,
                              PaymentModeName = u.PaymentModeName,
                              IsActive = u.IsActive
                          });
            return varRes.ToList();

        }
    }

    public int DA_InsertUpdatePaymentMode(PLPaymentMode pObjPaymentMode)
    {
        using (objABEnt = new AuditBillingEntities())
        {
            MstPaymentMode objPaymentMode = new MstPaymentMode();
            if (pObjPaymentMode.PaymentModeID.GetValueOrDefault() != 0)
            {
                objPaymentMode = (from u in objABEnt.MstPaymentModes
                                  where u.MstPaymentModeID == pObjPaymentMode.PaymentModeID
                                  select u).ToList().FirstOrDefault();
            }
            objPaymentMode.PaymentModeName = pObjPaymentMode.PaymentModeName;
            objPaymentMode.IsActive = pObjPaymentMode.IsActive;

            if (pObjPaymentMode.PaymentModeID.GetValueOrDefault() != 0)
            {
                objPaymentMode.ModifiedBy = SessionInfo.prop_getObj.EmployeeID;
                objPaymentMode.ModifiedOn = DateTime.Now;
            }
            else
            {
                objPaymentMode.CreatedBy = SessionInfo.prop_getObj.EmployeeID;
                objPaymentMode.CreatedOn = DateTime.Now;
                objABEnt.MstPaymentModes.Add(objPaymentMode);
            }
            objABEnt.SaveChanges();
            return objPaymentMode.MstPaymentModeID;
        }
    } 
}